package com.kungfuhacking.wristbandpro.net;


import com.kungfuhacking.wristbandpro.base.bean.HttpResult;
import com.kungfuhacking.wristbandpro.utils.Constant;

import io.reactivex.Observer;

/**
 * 自定义observer
 * Created by Aaron on 17/3/27.
 */

public abstract class BaseObserver<T> implements Observer<HttpResult<T>> {

    @Override
    public void onNext(HttpResult<T> value) {

        //网络返回的code不等于0,调用error

        if (value.getCode() == Constant.ERR0R_RELOGIN)
            onReLogin(value.getCode_msg());
//            onReLogin();
        else if (value.getCode() == 0)
            onHandleSuccess(value.getData());
        else
            onHandleError(value.getCode_msg());

    }

    @Override
    public void onError(Throwable e) {
        onHandleError("网络错误 : " + e.getMessage());
    }

    @Override
    public void onComplete() {
    }

    public abstract void onHandleSuccess(T t);

    public abstract void onHandleError(String message);

    public abstract void onReLogin(String message);
//    public abstract void onReLogin();

}
